﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
public partial class administrator_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(BLL.CmsBLL));
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            string Password= SecurityServices.GetMD5(txtPassword.Text.Trim());
            int CheckUserLogin = int.Parse("0" + new CmsBLL().Manager_CheckLogin(txtUserName.Text.Trim(), Password, DateTime.Now));           
            switch (CheckUserLogin)
            {
                case 0:
                    SecurityServices.SetCurrentUser(txtUserName.Text);
                    SecurityServices.SetCookie(chkRememberMe.Checked, txtUserName.Text, txtPassword.Text);
                    string retUrl = Request.QueryString["RetUrl"];
                    if (!string.IsNullOrEmpty(retUrl))
                        Response.Redirect(retUrl);
                    else
                        Response.Redirect("default.aspx");
                    break;
                case 1:
                    ltmessage.Text = "Tên đăng nhập hoặc mật khẩu chưa đúng!";
                    break;
                case 2:
                    ltmessage.Text = "Tài khoản của bạn đã bị khóa. <br>"+
                                    " "+new CmsBLL().Manager_GetLockedReason(txtUserName.Text.Trim())+ "";                    
                    break;
            }
        }
        catch (Exception ex)
        {
            ltmessage.Text = "ERROR: " + ex.Message.ToString();
        }        
       
    }    
    protected void btnQuit_Click(object sender, EventArgs e)
    {
        Response.Redirect("../default.aspx");
    }
}